<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2023/10/18
 * Time: 3:59 PM
 */

namespace app\zyhsapi\model;

class ZyhsCoupon extends BaseCacheZyhs
{
    protected $table = 'good_wechatadmin.zyhs_coupon';
    protected $cacheModel = 'coupon.attr';

    /**
     * 批量获取数据
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array|false|string|void
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            $data = $this->where(['id' => ['in', $ids]])->column('*', 'id');
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        return $data;
    }

    public function batchGetInfoByIds($cids, $field = [])
    {
        $resData = parent::batchGetInfoByIds($cids, $field);

        return $this->dataInit($resData);
    }

    /**
     * 数据初始化
     * @param array $data
     * @return array
     */
    public function dataInit(array $data)
    {
        foreach ($data as $index => $itemData)
        {
            $data[$index] = arrayKeyData2int($itemData, ['id', 'type', 'condition', 'discount', 'aid', 'create_time', 'update_time']);
        }

        return $data;
    }
}
